/*
 * Copyright (c) 2024 Soon.Liao. All rights reserved.
 * @Author: soon.liao
 * @Date: 2024-03-05 21:07:06
 * @LastEditors: soon.liao
 * @LastEditTime: 2025-03-17 20:24:07
 * @FilePath: \my-car\main\l9110s.h
 * @Description: Create Date : 2024
 * NA
 */
/*
 * @Author: soon.liao
 * @Date: 2024-02-05 21:44:50
 * @LastEditors: soon.liao
 * @LastEditTime: 2025-03-16 21:01:47
 * @FilePath: \my-car\main\l9110s.h
 * @Description: NA
 * NA
 * Copyright (c) 2024 by soon.liao  , All Rights Reserved.
 */
#ifndef __L9110S_H__
#define __L9110S_H__

#if CONFIG_IDF_TARGET_ESP32C3
#define MOTOR_LEFT_FRONT_FOR (GPIO_NUM_6)
#define MOTOR_LEFT_FRONT_BAK (GPIO_NUM_7)

#define MOTOR_LEFT_REAR_FOR (GPIO_NUM_4)
#define MOTOR_LEFT_REAR_BAK (GPIO_NUM_5)

#define MOTOR_RIGHT_FRONT_FOR (GPIO_NUM_0)
#define MOTOR_RIGHT_FRONT_BAK (GPIO_NUM_1)

#define MOTOR_RIGHT_REAR_FOR (GPIO_NUM_18)
#define MOTOR_RIGHT_REAR_BAK (GPIO_NUM_19)
#elif CONFIG_IDF_TARGET_ESP32S3

#define MOTOR_LEFT_FRONT_FOR (GPIO_NUM_9)
#define MOTOR_LEFT_FRONT_BAK (GPIO_NUM_14)

#define MOTOR_LEFT_REAR_FOR (GPIO_NUM_21)
#define MOTOR_LEFT_REAR_BAK (GPIO_NUM_42)

#define MOTOR_RIGHT_FRONT_FOR (GPIO_NUM_38)
#define MOTOR_RIGHT_FRONT_BAK (GPIO_NUM_39)

#define MOTOR_RIGHT_REAR_FOR (GPIO_NUM_40)
#define MOTOR_RIGHT_REAR_BAK (GPIO_NUM_41)
#endif

typedef enum
{
    LEFT_FRONT = 0, // 左前
    LEFT_REAR,      // 左后
    RIGHT_FRONT,    // 右前
    RIGHT_REAR      // 右后
} MotorPosition;

typedef enum
{
    STANDBY = 0, // 待机
    FOREWARD,    // 正转
    REVERSAL,    // 反转
    BRAKE        // 刹车
} MotorFunction;

void motor_l9110s_init(void);
void motor_l9110s_standby(MotorPosition position);                  // 待机
void motor_l9110s_foreward(MotorPosition position, uint32_t speed); // 正转
void motor_l9110s_reversal(MotorPosition position, uint32_t speed); // 反转
void motor_l9110s_brake(MotorPosition position);                    // 刹车

void motor_l9110s_control(MotorPosition position, MotorFunction function, uint32_t speed); // 四驱电机控制

#endif
